package get

import (
	"database/sql"
	"fmt"

	"github.com/gin-gonic/gin"
	_ "github.com/lib/pq"
)

func Get_user(r *gin.Engine) {
		var err error
		var db *sql.DB
		db, err = sql.Open("postgres", "port=5432 user=postgres password=system dbname=databasedesign sslmode=disable")
		var user_id, user_password string
		r.GET("/login", func(c *gin.Context) {
			// 获取参数
			user_id = c.Query("userid")
			user_password = c.Query(("userpassword"))
			c.JSON(200, gin.H{
				"userid":       user_id,
				"userpassword": user_password,
			})
	
		})
	
		fmt.Printf("%s%s", user_id, user_password)
	
		r.GET("/loginsuccess", func(c *gin.Context) {
			var code, str, sno, password string
			code = "0"
	
			if err != nil {
				panic(err)
			}
	
			str = "SELECT password FROM student where sno='" + user_id + "'"
			rows, err := db.Query(str)
			if err != nil {
				panic(err)
			}
			for rows.Next() {
				err = rows.Scan(&password)
				if err != nil {
					panic(err)
				}
			}
			if user_password == password {
				code = "10"
			}
			fmt.Printf("user:%s%s", sno, password)
			// 获取参数
			c.JSON(200, gin.H{
				"code":         code,
				"str":          str,
				"userpassword": user_password,
				"password":     password,
			})
		})
	}